<?php

class Frontend extends TST_Controller {

    protected $template = 'default';

    function Frontend() {
        parent::__construct();
        $this->output->enable_profiler(PROFILER);
        require_once(APPPATH . '/libraries/app-constants.php');

        //Default keyword search;
        $this->data['keywords'] = '';

        // Default css
        $this->layout[AppContants::LAYOUT_CSS] = array('bootstrap', 'style','navigation');
        //Default js
        $this->layout[AppContants::LAYOUT_JS] = array('jquery', 'bootstrap', 'owl.carousel', 'main', 'services');
        // Breadcrumb
        $this->layout[AppContants::BREADCRUMB] = NULL;

        $this->layout[AppContants::MENU_TASK] = NULL;
        $this->layout[AppContants::EMPLOYEE_MENU_TASK] = NULL;
        $this->layout[AppContants::LAYOUT_MENU_LEFT] = NULL;

        //Default active menu top
        $this->layout[AppContants::ACTIVE_MENU] = "";

        // Default meta header info
        $this->meta[AppContants::META_TITLE] = "Balatra";
        $this->meta[AppContants::META_KEYWORDS] = '';
        $this->meta[AppContants::META_DESCRIPTION] = '';

        $this->layout[AppContants::LAYOUT_MESSAGE_ACCOUNT] = NULL;
    }

    public function index() {
        
    }

    function recursive($menu, $parentid = 0, $level = 1, &$newArr) {
        if (!empty($menu)) {
            foreach ($menu as $key => $info) {
                if ($info['parent_id'] == $parentid) {
                    $info['level'] = $level;
                    $newArr[] = $info;
                    $newparentid = $info['id'];
                    unset($menu[$key]);
                    $this->recursive($menu, $newparentid, $level+1, $newArr);
                }
            }
        }
    }

    function Menu1($menu, $parentid = 0, &$str) {
        if (!empty($menu)) {
            if ($parentid == 0)
                $str .= '<ul class="nav navbar-nav">';
            else
                $str .= '<ul>';
            foreach ($menu as $key => $info) {
                if ($info['parent_id'] == $parentid) {
                    $class = 'class="level-'.$info['level'].'"';
                    $str.= '<li '.$class.'><a href="'.  base_url($info['friendly_url']).'">' . $info['name'] . '</a>';
                    $newparentid = $info['id'];
                    unset($menu[$key]);
                    $this->Menu1($menu, $newparentid, $str);
                    $str.='</li>';
                }
            }
            $str.= '</ul>';
        }
    }

    function Menu($parentid = 0, $space = '--', $trees = NULL) {
        if (!$trees)
            $trees = array();
        $sql = mysql_query("SELECT id, parent_id, name, friendly_url , type, level, status FROM category WHERE status <> 'delete' AND parent_id = " . intval($parentid));
        while ($rs = mysql_fetch_assoc($sql)) {
            $trees[] = array('id' => $rs['id'], 'name' => $space . '&nbsp;&nbsp;&nbsp;' . $rs['name'], 'level' => $rs['level'], 'friendly_url' => $rs['friendly_url'], 'type' => $rs['type'], 'status' => $rs['status']);
            $trees = $this->Menu($rs['id'], $space . '--', $trees);
        }
        return $trees;
    }

    public function print_debug($var) {
        echo '<pre>';
        print_r($var);
        echo '</pre>';
        die;
    }

    public function createBreadcrunb($page = null, $url = null) {
        $breadcrumb = array();
        $exp_page = explode("/", $page);
        $exp_url = explode("/", $url);
        $breadcrumb[0]['page'] = "";
        $breadcrumb[0]['url'] = "";
        if (count($exp_page) > 1) {
            for ($i = 1; $i < count($exp_url); $i++) {
                $breadcrumb[$i]['page'] = $exp_page[$i];
                $breadcrumb[$i]['url'] = $breadcrumb[$i - 1]['url'] . "/" . $exp_url[$i];
            }
        }
        return $breadcrumb;
    }

}

?>
